﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Account_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string name = LoginUser.UserName.Trim();
        string password = LoginUser.Password.Trim();

        TreasurerDataContext db = new TreasurerDataContext();
        var q = from aU in db.Users
                where aU.ID == name
                select aU;

        if (q.Count() == 0)
        {
            LoginUser.FailureText = "用户名输入错误，请重新输入。";
        }
        else
        {
            Users u = q.First();
            if (u.Password != password)
            {
                LoginUser.FailureText = "密码输入错误，请重新输入。";
            }
            else
            {
                e.Authenticated = true;
                Session["Current_User_Id"] = u.ID;
                Session["Current_User_Name"] = u.Name;
            }
        }
    }
}
